package com.runshu.newsmartark.util.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.runshu.newsmartark.R;
import com.runshu.newsmartark.util.ImageUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * <pre>
 *     time   : 2017/08/15
 *     desc   : 普通的类似ios的对话框
 *     version: 1.0   初始化
 *     params:
 *  <pre>
 */

public class CommonQRDialog extends Dialog {
    @BindView(R.id.img_dialog_show)
    ImageView mImgDialogShow;
    @BindView(R.id.tv_dialog_show)
    TextView mTvDialogShow;
    @BindView(R.id.tv_dialog_show_hint)
    TextView mTvDialogShowHint;
    @BindView(R.id.img_back)
    ImageView mImgBack;
    @BindView(R.id.img_qr_code)
    ImageView mImgQrCode;
    private Context mContext;
    private View.OnClickListener onClickListenerCancel;

    public CommonQRDialog(@NonNull Context context) {
        super(context, R.style.dialog_untran);
        mContext = context;
        setContentView(R.layout.dialog_qr_show);
        ButterKnife.bind(this);
        this.setOnShowListener(new OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {

            }
        });
    }

    private String content;
    private String contentHint;

    private int imgShow;

    private String imgResour;

    /**
     * 设置内容    默认为空
     *
     * @param content
     */
    public void setContent(String content) {
        this.content = content;
    }

    public void setContentHint(String contentHint) {
        this.contentHint = contentHint == null ? "" : contentHint;
    }

    public void setImgResour(String imgResour) {
        this.imgResour = imgResour;
    }

    /**
     * 设置内容    默认为空
     *
     * @param imgShow
     */
    public void setImgShow(int imgShow) {
        this.imgShow = imgShow;
    }


    @Override
    public void show() {
        mTvDialogShow.setText(content);
        mImgDialogShow.setImageResource(imgShow);
        mTvDialogShowHint.setText(contentHint);
        ImageUtil.loadNormalImage(mContext, imgResour, mImgQrCode);
        super.show();
    }

    private void setButtonOnClickListener(ImageView imageView, View.OnClickListener onClickListener) {
        if (imageView == null) {
            return;
        }
        if (onClickListener == null) {
            onClickListener = onClickListenerDismiss;
        }
        imageView.setOnClickListener(onClickListener);

    }

    private View.OnClickListener onClickListenerDismiss = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    };

    /**
     * 取消按钮事件监听 默认是dismiss对话框
     *
     * @param onClickListenerCancel
     */
    public void setOnClickListenerCancel(View.OnClickListener onClickListenerCancel) {
        if (mImgBack != null)
            setButtonOnClickListener(mImgBack, onClickListenerCancel);
        this.onClickListenerCancel = onClickListenerCancel;
    }


}
